package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC中的事务控制
 */
public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection con=DBUtil.getConnection();){
            con.setAutoCommit(false);

            String sql="DELETE FROM userinfo WHERE id=3 ";
            Statement state=con.createStatement();
            int num=state.executeUpdate(sql);
            System.out.println(num>0?"删除成功":"删除失败");
            con.commit();//COMMIT
            System.out.println("事务提交了");
//            con.rollback();
//            System.out.println("事务回滚了");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
